< previous page page_509 next page >

Page 509
Next, the mboolAdding variable is checked to see whether the new employee needs to be added to the list box. Because ADO currently has a problem retrieving the value generated by the AutoNumber or IDENTITY type fields, its best to just reload the list box. However, you should position the list box to the new employee you just added. To do this, you need to save the last name and first name from the text boxes into a string variable and then use it to set the Text property of the list box immediately after the list box is reloaded. This positions the list box to the new employee record just added.
Lets take a look at the FieldsSave procedure. Here, youll see functions that are the opposite of the functions that converted the data on the way out of the recordset. For example, the Str2Field() function is the opposite of the Field2Str() function. In the Str2Field() function, the text box is checked to see whether the value is blank. If it is, the value thats returned from the Str2Field() function is a Null value. Heres the code:
9f31265bb40b592b1929e18a47ab28e5.gif
Private Sub FieldsSave()
   With moRS
      !sFirst_nm = Str2Field(txtFirst)
      !szLast_nm = Str2Field(txtLast)
      !szStreet1_ad = Str2Field(txtAddress)
      !szCity_nm = Str2Field(txtCity)
      !lState_id = cboStates.ItemData(cboStates.ListIndex)
      !sZip_cd = Str2Field(txtZip)
      !sPhone_no = Str2Field(txtPhone)
      !sSSN_tx = Str2Field(txtSSN)
      !dtBirth_dt = Date2Field(txtBirthDate)
      !cSalary_amt = Str2Field(txtSalary)
      If optMale.Value Then
         !sSex_Type = "M"
      Else
         !sSex_Type = "F"
      End If
      !boolHealth_fl = (chkHealth.Value = vbChecked)
      !bool401k_fl = (chk401k.Value = vbChecked)
      !boolBonus_fl = (chkBonus.Value = vbChecked)
   End With
End Sub

 
< previous page page_509 next page >

If you like this book, buy it!